package com.lpf.json.fastjson.empty;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class TestNull {

	public static void main(String[] args) {

		// WriteNullListAsEmpty 将Collection类型字段的字段空值输出为[]
		// WriteNullStringAsEmpty 将字符串类型字段的空值输出为空字符串 ""
		// WriteNullNumberAsZero 将数值类型字段的空值输出为0
		// WriteNullBooleanAsFalse 将Boolean类型字段的空值输出为false

		Model obj = new Model();

		System.out.println("------------------加上参数------------------------------");
		String text = JSON.toJSONString(obj, 
				SerializerFeature.WriteNullListAsEmpty, 
				SerializerFeature.WriteNullStringAsEmpty,
				SerializerFeature.WriteNullNumberAsZero,
				SerializerFeature.WriteNullBooleanAsFalse,
				SerializerFeature.WriteMapNullValue,
				SerializerFeature.PrettyFormat);

		System.out.println(text + " \n");
		
		System.out.println("------------------不加参数------------------------------");
		text = JSON.toJSONString(obj,
				SerializerFeature.PrettyFormat);

		System.out.println(text);
	}

}

class Model {
	public int iFull = 9;
	public int iEmpty;

	public Integer integerFull = 9;
	public Integer integerEmpty;
	
	public boolean bFull = true;
	public boolean bEmpty;
	
	public Boolean BFull = true;
	public Boolean BEmpty;

	public List<String> listFull = Arrays.asList("挖", "坑", "埋", "你");
	public List<String> listEmpty;

	public Map<String, String> mapFull = new HashMap<String, String>() {{put("a", "b");}};
	public Map<String, String> mapEmpty;

}